﻿#include "DialogInterpolation.h"
#include "ui_DialogInterpolation.h"
#include "IdaWidgetHelper.h"
#include "CenterWidget.h"
#include "LineChartWindow.h"
#include "PostEnumType.h"
#include <QDebug>
#include "BaseModule/IBaseSignal.h"

namespace pst
{
    DialogInterpolation::DialogInterpolation(QWidget* parent, LineChartWindow* lineChartWindow)
        : IdaDialogFrame(parent)
        , ui(new Ui::DialogInterpolation())
    {
        ui->setupUi(this);
        m_lineChartWindow = lineChartWindow;
        setWindowTitle(tr("插值"));
        IdaWidgetHelperInstance->setMainButtonStyle(ui->pushButton_confirm); // 将确定设置为主按钮
    }

    DialogInterpolation::~DialogInterpolation()
    {
        delete ui;
    }

    void DialogInterpolation::on_pushButton_confirm_clicked()
    {
        if (m_lineChartWindow == nullptr)
            return;

        int interpolationType = static_cast<int>(m_interpolationType);

        int state = m_lineChartWindow->slot_interpolationData(ui->spinBox->value(), m_interpolationType);
        if (state == 0)
        {
            QString _pyCode = QString("PostProcessing.lineChartDialogInterpolation(%1,%2)").arg(ui->spinBox->value()).arg(interpolationType);
            emit IBaseSignalInstance->signal_execPYCode(QStringList{ _pyCode }, true, false);
        }
        else if (state == 1)
        {
            IBaseSignalInstance->signal_sendErrorMessageToUI("存在X小于0的坐标值，不满足单X轴对数插值条件");
        }
        else if (state == 2)
        {
            IBaseSignalInstance->signal_sendErrorMessageToUI("存在Y小于0的坐标值，不满足单Y轴对数插值条件");
        }
        else if (state == 3)
        {
            IBaseSignalInstance->signal_sendErrorMessageToUI("存在X或Y小于0的坐标值，不满足双对数插值条件");
        }
        this->close();
    }

    void DialogInterpolation::on_pushButton_cancel_clicked()
    {
        this->close();
    }

    void DialogInterpolation::setInterpolationType(InterpolationType type) 
    {
        m_interpolationType = type;
        //需更新windowTitle
    }

    void DialogInterpolation::setInit(QStringList& params)
    {
        if (params.at(0) != "7" && params.at(0) != "8" && params.at(0) != "9" && params.at(0) != "10")
            return;
        params.removeFirst();
        ui->spinBox->setValue(params.first().toInt());
    }
}
